//
//  SFNavigationController.swift
//  SFWeiboPro
//
//  Created by happy on 2017/9/6.
//  Copyright © 2017年 happy. All rights reserved.
//

import UIKit

class SFNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //隐藏导航栏
        navigationBar.isHidden = true
        
//        print("navigationBar = \(navigationBar.bounds)")
    }

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            
            if let vc = viewController as? SFBaseViewController {
                
                var title = "返回"
                
                if childViewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? "返回"
                }
                
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToParent), isBack: true)
            }
        }
        
        super.pushViewController(viewController, animated: true)
    }
    
    @objc func popToParent() {
        popViewController(animated: true)
    }
}
